#!/bin/bash

echo "🚀 启动Java后端服务..."

cd backend

echo "📦 编译Java项目..."
mvn clean package -DskipTests -q

if [ ! -f "target/autorun-server-1.0.0.jar" ]; then
    echo "❌ 编译失败，未找到JAR文件"
    exit 1
fi

echo "🔧 设置环境变量..."
export DB_NAME=autorun_db
export SERVER_PORT=8891
export JWT_SECRET=autorun-script-control-center-jwt-secret-2024

echo "▶️  启动Java后端服务 (端口: 8891)..."
nohup java -jar target/autorun-server-1.0.0.jar > ../backend.log 2>&1 &
echo "✅ 后端服务已启动 (PID: $!)"
echo "   API地址: http://localhost:8891"
echo "   日志文件: backend.log"